class CommentsController < ApplicationController
	def new
		@micropost = Micropost.find(params[:micropost_id])
		@comment = @micropost.comments.build
	end

	def  create
		@micropost = Micropost.find(comment_params[:micropost_id])
    		@comment = @micropost.comments.create(comment_params)
    		redirect_to user_path(@micropost.user)
	end

	def destroy
		@comment = Comment.find(params[:id])
		@comment.destroy
		flash[:success] = "Comment deleted"
		redirect_to request.referrer || root_url
	end

	private
    	def comment_params
     	params.require(:comment).permit(:content,:micropost_id,:user_id)
    	end
end
